﻿using House.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using House.DTO;
using House.Service.Entities;

namespace House.Service
{

    public class Permission : BaseService<T_Permissions>,IPermission
    {
        public Permission():base(new Model())
        {

        }

        public List<PermissionDTO> GetList(int start, int length, string name, ref long rowCount)
        {
            var list = GetPagedList(start, length, ref rowCount, p => p.Name.Contains(name), p => p.CreateDateTime, false);
            return list.Select(p => new PermissionDTO()
            {
                Id = p.Id,
                Name = p.Name,
                Description = p.Description
                //throw new NotImplementedException();
            }).ToList();
        }
        public List<string> GetPermissionByUserId(long id)
        {
            var user = DB.T_AdminUsers.FirstOrDefault(p=>p.Id==id);
            var roles = user.T_Roles;
            List<string> per = new List<string>();
            foreach (var role in roles)
            {
                var pers = role.T_Permissions.Select(p=>p.Name);
            }
            return per;
        }
    }
}
